Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New text tool #4383

Draft
wants to merge 9 commits into
base: beta
Choose a base branch
from
Draft

New text tool #4383

wants to merge 9 commits into from

Conversation

dacap
Copy link
Member

@dacap dacap commented Mar 25, 2024

A work-in-progress to convert the "insert text" command into an interactive "text tool."

This was linked to issues Mar 25, 2024
aseprite-bot

This comment was marked as outdated.

aseprite-bot

This comment was marked as outdated.

aseprite-bot

This comment was marked as outdated.

@dacap dacap force-pushed the new-text-tool branch 2 times, most recently from 6e06e9a to e7931fb Compare June 13, 2024 12:44
Copy link
Collaborator

@aseprite-bot aseprite-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

doc::BlendMode::SRC);
}

void renderExtraCelText(bool withSelection) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: parameter 'withSelection' is unused [misc-unused-parameters]

Suggested change
void renderExtraCelText(bool withSelection) {
void renderExtraCelText(bool /*withSelection*/) {


void WritingTextState::onEditorResize(Editor* editor)
{
gfx::PointF scale(editor->projection().scaleX(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'scale' of type 'gfx::PointF' (aka 'PointT') can be declared 'const' [misc-const-correctness]

Suggested change
gfx::PointF scale(editor->projection().scaleX(),
gfx::PointF const scale(editor->projection().scaleX(),


void WritingTextState::onEditorResize(Editor* editor)
{
gfx::PointF scale(editor->projection().scaleX(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: narrowing conversion from 'double' to 'float' [bugprone-narrowing-conversions]

  gfx::PointF scale(editor->projection().scaleX(),
                    ^

void WritingTextState::onEditorResize(Editor* editor)
{
gfx::PointF scale(editor->projection().scaleX(),
editor->projection().scaleY());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: narrowing conversion from 'double' to 'float' [bugprone-narrowing-conversions]

                    editor->projection().scaleY());
                    ^

src/ui/entry.cpp Outdated
@@ -235,6 +236,17 @@ gfx::Rect Entry::getEntryTextBounds() const
return onGetEntryTextBounds();
}

gfx::Rect Entry::getCharBoxBounds(const int charBoxIndex)
{
gfx::Rect bounds;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'bounds' of type 'gfx::Rect' (aka 'RectT') can be declared 'const' [misc-const-correctness]

Suggested change
gfx::Rect bounds;
gfx::Rect const bounds;

src/ui/entry.cpp Outdated
@@ -569,7 +581,8 @@
indexBox = j+1;
}

int x = bounds().x + border().left() + segmentWidth + m_boxes[indexBox].width / 2;
int x = bounds().x + border().left()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'x' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int x = bounds().x + border().left()
int const x = bounds().x + border().left()

src/ui/entry.cpp Outdated
@@ -569,7 +581,8 @@
indexBox = j+1;
}

int x = bounds().x + border().left() + segmentWidth + m_boxes[indexBox].width / 2;
int x = bounds().x + border().left()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: narrowing conversion from 'float' to 'int' [bugprone-narrowing-conversions]

    int x = bounds().x + border().left()
            ^

src/ui/entry.cpp Outdated
@@ -569,7 +581,8 @@
indexBox = j+1;
}

int x = bounds().x + border().left() + segmentWidth + m_boxes[indexBox].width / 2;
int x = bounds().x + border().left()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: narrowing conversion from 'int' to 'float' [bugprone-narrowing-conversions]

    int x = bounds().x + border().left()
            ^

@@ -569,7 +581,8 @@
indexBox = j+1;
}

int x = bounds().x + border().left() + segmentWidth + m_boxes[indexBox].width / 2;
int x = bounds().x + border().left()
+ (segmentWidth + m_boxes[indexBox].width / 2) * m_scale.x;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: narrowing conversion from 'int' to 'float' [bugprone-narrowing-conversions]

      + (segmentWidth + m_boxes[indexBox].width / 2) * m_scale.x;
        ^

@@ -569,7 +581,8 @@
indexBox = j+1;
}

int x = bounds().x + border().left() + segmentWidth + m_boxes[indexBox].width / 2;
int x = bounds().x + border().left()
+ (segmentWidth + m_boxes[indexBox].width / 2) * m_scale.x;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: result of integer division used in a floating point context; possible loss of precision [bugprone-integer-division]

      + (segmentWidth + m_boxes[indexBox].width / 2) * m_scale.x;
                        ^

@dacap dacap force-pushed the new-text-tool branch 2 times, most recently from 2890ebf to 5591a59 Compare June 19, 2024 20:03
This new font selector list installed fonts with its proper name. It
still needs some extra work to select font set styles (regular, bold,
italic, etc.)
If we clicked bold/italic, and then chose another font family, we were
using the cached typeface inside the FontInfo instead of an update
typeface with the selected styles applied (bold/italic).

Now we don't cache the typeface inside FontInfo to avoid this.
This fixes the required output image size to render text in different
languages when the text doesn't support the full range of the
specified chars/code points, and multiple fonts/text runs are used.
This is the first (not yet production-ready) version of the
interactive Text tool. The text input is done with a transparent
ui::Entry, and on each text modification an ExtraCel is rendered with
this same ui::Entry's TextBlob to be displayed in the canvas with the
active zoom level.

The ui::Entry is being painted along the text in the canvas (just for
testing), but this is something to be fixed. Probably it will not be
the case in the future and a fully customized rendering (onPaint())
process will be required.
Now we don't render the default ui::Entry edges, but we paint just a
border of the text bounds + the rendered text highlighting selected
text on the canvas itself.

With this change click mouse positions are translated with a scale
factor that changes depending on the app::Editor zoom.
Copy link
Collaborator

@aseprite-bot aseprite-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions


void WritingTextState::onEditorResize(Editor* editor)
{
const gfx::PointF scale(editor->projection().scaleX(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: narrowing conversion from 'double' to 'float' [bugprone-narrowing-conversions]

  const gfx::PointF scale(editor->projection().scaleX(),
                          ^

void WritingTextState::onEditorResize(Editor* editor)
{
const gfx::PointF scale(editor->projection().scaleX(),
editor->projection().scaleY());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: narrowing conversion from 'double' to 'float' [bugprone-narrowing-conversions]

                          editor->projection().scaleY());
                          ^

@@ -569,7 +580,8 @@ int Entry::getCaretFromMouse(MouseMessage* mousemsg)
indexBox = j+1;
}

int x = bounds().x + border().left() + segmentWidth + m_boxes[indexBox].width / 2;
const int x = bounds().x + border().left()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: narrowing conversion from 'float' to 'int' [bugprone-narrowing-conversions]

    const int x = bounds().x + border().left()
                  ^

@@ -569,7 +580,8 @@ int Entry::getCaretFromMouse(MouseMessage* mousemsg)
indexBox = j+1;
}

int x = bounds().x + border().left() + segmentWidth + m_boxes[indexBox].width / 2;
const int x = bounds().x + border().left()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: narrowing conversion from 'int' to 'float' [bugprone-narrowing-conversions]

    const int x = bounds().x + border().left()
                  ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New font selector Textbox tool
2 participants